#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    bool Isletter(const string& s, size_t i)
    {
        if (s[i] >= 65 && s[i] <= 90 || s[i] >= 97 && s[i] <= 122)
        {
            return true;
        }
        return false;
    }
    string reverseOnlyLetters(string s) {
        size_t begin = 0;
        size_t end = s.size() - 1;
        while (begin < end)
        {
            while (!Isletter(s, begin) && begin < end)
            {
                ++begin;
            }
            while (!Isletter(s, end) && begin < end)
            {
                --end;
            }
            swap(s[begin++], s[end--]);
        }
        return s;
    }
};
int main()
{
	string S1("ab+cd+ef!=x");
    Solution s;
    S1 = s.reverseOnlyLetters(S1);
    cout << S1 << endl;
	return 0;
}